{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e6efd0b5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 'lulu']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x=[]\n",
    "[1,2,3,4,'lulu']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "897ebebd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list (range(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7149e3cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 3, 5, 7, 9]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(1,10,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e98104fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst=[1,2,3]\n",
    "lst[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a1471d53",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 5, 3]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst[1]=5\n",
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d92d10d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 5, 3, 3, 'abc']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst2=[3,'abc']\n",
    "list=lst+lst2\n",
    "list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f3743421",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 1, 2, 1, 2, 1, 2, 1, 2]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[1,2]*5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "64503ee8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 in lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "09a910a6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "5\n",
      "3\n",
      "3\n",
      "abc\n"
     ]
    }
   ],
   "source": [
    "for x in list:\n",
    "    print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "18426b06",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输入小于10的奇数:3\n",
      "输入正确\n"
     ]
    }
   ],
   "source": [
    "newlst=[1,3,5,7,9]\n",
    "x = int(input('输入小于10的奇数:'))\n",
    "if x in lst:\n",
    "    print('输入正确')\n",
    "else:\n",
    "    print('输入不正确')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "2897cb86",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 5, 3, 3, 'abc', 88, 88]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list.append(88)\n",
    "list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "3bf3bb30",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list.index(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b1245082",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list.count(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "176b5640",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 3]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del lst[1]\n",
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "657dc8bb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 'abc']"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "7f993ff7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 5, 5, 3, 3, 3, 'abc', 3, 'abc']"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst.extend(lst2)\n",
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "65555719",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for +: 'int' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [38]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;43msum\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mlst\u001b[49m\u001b[43m)\u001b[49m\n",
      "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'str'"
     ]
    }
   ],
   "source": [
    "sum(lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "13c98dda",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 5, 3, 3, 3, 'abc', 3, 'abc']"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del lst[2]\n",
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "60e0975e",
   "metadata": {},
   "outputs": [],
   "source": [
    "del lst[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "ca18f14b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 5, 3, 3, 3, 'abc']"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del lst[4]\n",
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "b0aa7771",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 5, 3, 3, 3]"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del lst[5]\n",
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "3d5a06fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 5, 3, 3]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del lst[4]\n",
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "5716cde1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum (lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "83e1a30d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.0"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum(lst)/len(lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "0b946879",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 5, 3, 3]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "6962ca16",
   "metadata": {},
   "outputs": [],
   "source": [
    "while 3 in lst:\n",
    "    lst.remove(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "6bc6c086",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 5]"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "08f6d601",
   "metadata": {},
   "outputs": [],
   "source": [
    "lst2=[3,4,2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "cd77ab33",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 5, 3, 4, 2]"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst.extend(lst2)\n",
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "425e5d84",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst.sort()\n",
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "cd4bc6b3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3, 4]"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst[1:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "3db9fc9c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3, 4, 5]"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst[1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "66a43772",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4]"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst[:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "bd863e9e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3, 4]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst[-4:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "ffdb4304",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[4, 3, 2]"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst[3:0:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "ff8d0a79",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[x*x for x in range(1,11)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "f46efac3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[4, 16, 36, 64, 100]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[x*x for x in range(1,11) if x % 2 == 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "d672c370",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "平均值为： 4.04\n",
      "1的个数为 11\n",
      "0的个数为10\n",
      "1的个数为11\n",
      "2的个数为14\n",
      "3的个数为10\n",
      "4的个数为9\n",
      "5的个数为13\n",
      "6的个数为13\n",
      "7的个数为10\n",
      "8的个数为4\n",
      "9的个数为6\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "lst=[random.randint(0,9)  for _ in range(100)]\n",
    "print('平均值为：',sum(lst)/len(lst))\n",
    "print('1的个数为', lst.count(1))\n",
    "\n",
    "for x in range(10):\n",
    "    print('{}的个数为{}'.format(x,lst.count(x)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8d242b0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
